www.gusucode.com > MATLAB神经网络实例与精析随书源程序 > 第11章 用GUI设计神经网络/fit_test.m
%fit_test.m % Solve an Input-Output Fitting problem with a Neural Network % Script generated by NFTOOL % Created Sun Mar 11 15:31:43 CST 2012 % % This script assumes these variables are defined: % % x - input data. % y - target data. % 自定义语句------------------------------ x=0:.2:2*pi+.2; rng(2);y=sin(x)+rand(1,length(x))*0.5; plot(x,y,'o-'); %----------------------------------------- inputs = x; targets = y; % Create a Fitting Network hiddenLayerSize = 10; net = fitnet(hiddenLayerSize); % Setup Division of Data for Training, Validation, Testing net.divideParam.trainRatio = 70/100; net.divideParam.valRatio = 15/100; net.divideParam.testRatio = 15/100; % Train the Network [net,tr] = train(net,inputs,targets); % Test the Network outputs = net(inputs); errors = gsubtract(targets,outputs); performance = perform(net,targets,outputs) % View the Network view(net) % 自定义语句----------------------------- xx=0:.1:2*pi+.2; yy=sin(xx)+0.25; yx=net(xx); plot(x,y,'o'); hold on; plot(xx,yy,'g-'); plot(xx,yx,'r+'); legend('训练样本','正弦曲线出','实际输出'); %---------------------------------------- % Plots % Uncomment these lines to enable various plots. %figure, plotperform(tr) %figure, plottrainstate(tr) %figure, plotfit(net,inputs,targets) %figure, plotregression(targets,outputs) %figure, ploterrhist(errors)